package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.R;
import com.atguigu.eduservice.client.VodClient;
import com.atguigu.eduservice.entity.EduVideo;
import com.atguigu.eduservice.service.EduVideoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-12-25
 */
@RestController
@RequestMapping("/eduservice/edu-video")
public class EduVideoController {

    private static final Logger logger = LoggerFactory.getLogger(EduVideoController.class);
    @Autowired
    private EduVideoService videoService;


    /**
     * 添加小结
     * @param eduVideo
     * @return
     */
    @PostMapping("addVideo")
    public R addVideo(@RequestBody EduVideo eduVideo){
        videoService.save(eduVideo);
        return R.ok();
    }

    /**
     * 删除小结
     * @param videoId
     * @return
     * TODO 后面这个方法需要完善：删除小结的时候，同时把里面的视频删除
     */
    @DeleteMapping("deleteVideo/{videoId}")
    public R deleteVideo(@PathVariable String videoId){
        videoService.removeVideosById(videoId);
        return R.ok();
    }

    /**
     * 修改小结
     * @param eduVideo
     * @return
     */
    @PutMapping("updateVideo")
    public R updateVideo(@RequestBody EduVideo eduVideo){
        videoService.updateById(eduVideo);
        return R.ok();
    }

    /**
     * 根据id查询小结
     * @param videoId
     * @return
     */
    @GetMapping("selectById/{videoId}")
    public R selectById(@PathVariable String videoId){
        EduVideo byId = videoService.getById(videoId);
        return R.ok().data("video",byId);
    }

}

